package com.tang.service.impl;

import com.tang.service.ILottyService;
import com.tang.service.MiniBusTargetService;
import com.tang.vo.LotteryResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;

public class LotteryServiceImpl implements ILottyService {

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    private final MiniBusTargetService miniBusTargetService;

    public LotteryServiceImpl() {
        this.miniBusTargetService = new MiniBusTargetService();
    }

    @Override
    public LotteryResult doDraw(String uId) {
        // 摇号
        String lottery = miniBusTargetService.lottery(uId);
        // 发短信
        log.info("给用户{}发送短信通知（短信）：{}", uId, lottery);
        // 发MQ消息
        log.info("记录用户{}摇号结果（MQ）：{}", uId, lottery);
        // 结果
        return new LotteryResult(uId, lottery, LocalDateTime.now());
    }
}
